Reference
  Area\Util.txt
  Util\Audio.txt
  Area\Service.txt
  Util\Party.txt
  Util\CommonDialog.txt
  Util\VisualEffect.txt
End Reference

Procedure Main(startAt)

  Dim ac = Nothing

  RegisterCommonEventHandlers()

  SetZoneOfTown(48, 48, 1, 1, 46, 46, ExitArea_Enter)

  ac = AddActor_MTStopped("EqShopper", 34, 28, 0, [A_Man], ActorMotion.Down, Nothing)
  ac = AddStaticActor("EqShopperEve", 34, 29, 10, [A_Null], EqShopperEve_Contact)

  ac = AddActor_MTStopped("MgShopper", 36, 28, 0, [A_OldMan], ActorMotion.Down, Nothing)
  ac = AddStaticActor("MgShopperEve", 36, 29, 10, [A_Null], MgShopperEve_Contact)

  ac = AddActor_MTStopped("GdShopper", 29, 17, 0, [A_Woman], ActorMotion.Down, Nothing)
  ac = AddStaticActor("GdShopperEve", 29, 18, 10, [A_Null], GdShopperEve_Contact)

  ac = AddActor_MTStopped("InnFront", 27, 17, 0, [A_Man], ActorMotion.Down, Nothing)
  ac = AddStaticActor("InnFrontEve", 27, 18, 10, [A_Null], InnFrontEve_Contact)

  If startAt = "Ending2" Then
    ac = AddActor_MTStopped("Father", 14, 5, 0, [A_Father], ActorMotion.Left, Nothing)
    ac = AddActor_MTStopped("Mother", 18, 4, 0, [A_Mother], ActorMotion.Up, Nothing)
  Else
    ac = AddActor_MTZonedRandom("Father", 16, 5, 0, _
      14, 3, 0, 20, 7, 0, [A_Father], Father_Contact)
    ac = AddActor_MTZonedRandom("Mother", 18, 5, 0, _
      14, 3, 0, 20, 7, 0, [A_Mother], Mother_Contact)
  End If
  
  ac = AddActor_MTZonedRandom("Towner1", 41, 5, 0, _
    38, 3, 0, 44, 7, 0, [A_Man], Towner1_Contact)
  
  ac = AddActor_MTZonedRandom("Towner2", 17, 40, 0, _
    14, 38, 0, 20, 42, 0, [A_Woman], Towner2_Contact)
  
  ac = AddActor_MTZonedRandom("Towner3", 41, 40, 0, _
    38, 38, 0, 44, 42, 0, [A_OldMan], Towner3_Contact)
  
  If startAt = "Ending2" Then
    RegisterEventHandler("Ending2", AS_Ending2)
    RaiseEvent("Ending2")
    DoInsideWarp("Entrance", SetEntranceEx({24, 1, 0}, {24, 46, 0}, {1, 12, 0}, {46, 23, 0}), False)
  Else
    DoInsideWarp(startAt, SetEntranceEx({24, 1, 0}, {24, 46, 0}, {1, 12, 0}, {46, 23, 0}), False)
    ChangeBGM(Music.Town)
  End If
  
  PutAreaNameLabel()

  NotifyEntered()
  Idle(ProcessInput)
  NotifyExiting()

End Procedure

Procedure ExitArea_Enter()
  BeginOutsideWarp([Field], GetAreaObject().Tag)
End Procedure

Procedure EqShopperEve_Contact()
  DoShop({[BronzeSword], [IronSword], [LeatherArmor], [BronzeArmor], [LeatherShield], [BronzeShield], [LeatherHelmet], [BronzeHelmet]})
End Procedure

Procedure MgShopperEve_Contact()
  DoMagicShop({[Heal1], [Fire1], [Cold1], [Panic], [Blind], [MagicalSword], [CureAll], [Elec1], [AgiUp], [AgiDown], [Paralyze], [Blink]})
End Procedure

Procedure GdShopperEve_Contact()
  DoShop({[Heal_T1], [Heal_T2], [CureAll_T], [Revive_T]})
End Procedure

Procedure InnFrontEve_Contact()
  DoInn(20)
End Procedure

Procedure Father_Contact()
  Dim q_name = "ギュンター："
  If TestFlag("Rabro_1") Then
    DoMsg(q_name, "カウレは北北西の方角にある", _
    "北西に大きな湖があるから", _
    "その東側の岸にそって北上すればいい")
  Else
    DoMsg(q_name, "行ってきたか", _
      "え？　カウレまで遣いを頼まれたって？")
    Sleep(500)
    DoMsg(q_name, "仕方ないな　早く行って来い", _
      "カウレはここからだと北北西だ", _
      "北西に大きな湖があるから", _
      "その東側の岸にそって北上すればいい")
    SetFlag("Rabro_1")
  End If
End Procedure

Procedure Mother_Contact()
  Dim p_name = [TheHero].Name + "："
  Dim q_name = "テレーゼ："
  If TestFlag("Rabro_2") Then
    DoMsg(q_name, "それじゃ　がんばってね")
  Else
    DoMsg(q_name, "おかえり", _
      "プラマールまで行ってきたのね")
    Sleep(500)
    DoMsg(q_name, "今度はカウレに行くの？　大変ね")
    DoMsg(q_name, "あ　そうそう", _
      "このガーネットのペンダントを", _
      "あげるから　付けていきなさい")
    DoMsg(p_name, "これは母さんの宝物……")
    DoMsg(q_name, "いいの　" + [TheHero].Name + "にあげる", _
      "いつかきっと　役立つ時が来るから")
    DoMsg(p_name, "ありがとう　母さん", _
      "大切にするよ")
    DoMsg(q_name, "それじゃ　がんばってね")
    SetFlag("Rabro_2")
  End If
End Procedure

Procedure Towner1_Contact()
  DoMsg("西の洞窟には何があるのだろう")
End Procedure

Procedure Towner2_Contact()
  DoMsg("いい天気ですね")
End Procedure

Procedure Towner3_Contact()
  DoMsg("景気悪いのう")
End Procedure

Procedure EndingMovingProc(a)
  For i = 1 To 8
    LetActorWalk(a, Direction.Down)
  Next
End Procedure

Procedure AS_Ending2()
  Dim ss = GetScreenSize()
  Dim p_name = [TheHero].Name + "："
  Dim q_name = "ギュンター："
  Dim r_name = "テレーゼ："
  Dim s_name = "レナード："
  For i = 1 To 10
    LetActorWalk(GetPrimaryActor(), Direction.Down)
  Next
  For i = 1 To 7
    LetActorWalk(GetPrimaryActor(), Direction.Left)
  Next
  LetActorTurn(GetPrimaryActor(), Direction.Up)
  Sleep(1500)
  For i = 1 To 4
    LetActorWalk(GetPrimaryActor(), Direction.Up)
  Next
  DoMsgT({p_name, "ただいま"}, 3000)
  LetActorTurn(GetActor("Father"), Direction.Down)
  LetActorTurn(GetActor("Mother"), Direction.Down)
  DoMsgT({q_name, "あ！"}, 2700)
  For i = 1 To 3
    LetActorWalk(GetActor("Father"), Direction.Right)
  Next
  LetActorWalk(GetActor("Father"), Direction.Down)
  Sleep(1500)
  DoMsgT({q_name, "ばかもの！　どこへ行っていたのだ！"}, 4100)
  DoMsgT({p_name, "ちょっと　大陸のほうまで……"}, 4000)
  For i = 1 To 3
    LetActorWalk(GetActor("Mother"), Direction.Down)
  Next
  LetActorTurn(GetActor("Mother"), Direction.Left)
  LetActorTurn(GetPrimaryActor(), Direction.Right)
  DoMsgT({r_name, "ケガはしてない？　大丈夫？"}, 3900)
  DoMsgT({p_name, "大丈夫だよ"}, 3300)
  LetActorTurn(GetPrimaryActor(), Direction.Up)
  DoMsgT({q_name, "まあ　無事ならいい", _
    "明日から工房に入れよ"}, 6000)
  Sleep(1500)
  FadeIn(0, 0, 0, 3000)
  If Not TestFlag("Medrod_1") AndAlso Not TestFlag("NorthEvo") Then
    DoMsgT({"それから" + [TheHero].Name + "は", _
      "剣を置いて　職人の道に進んだ"}, 6000)
    Sleep(1500)
    DoMsgT({"怪物も消え　世界は平和を享受していた"}, 4400)
    Sleep(1500)
    DoMsgT({"この世界を救った　若き剣士の事など", _
      "誰も知らずに"}, 6100)
    Sleep(1500)
    DoMsgT({"誰も？……"}, 7000)
    Sleep(1500)
    GoTo End_Roll
  End If
  DoMsgT({"それから半年ほど", _
    [TheHero].Name + "はギュンターのもとで", _
    "パン作りの手伝いをしていた"}, 7000)
  Sleep(1500)
  DoMsgT({"怪物も消え　世界は平和を享受していた"}, 4400)
  Sleep(1500)
  LetActorWalk(GetActor("Father"), Direction.Right)
  For i = 1 To 3
    LetActorWalk(GetActor("Father"), Direction.Up)
  Next
  For i = 1 To 3
    LetActorWalk(GetActor("Mother"), Direction.Up)
    LetActorWalk(GetActor("Mother"), Direction.Left)
  Next
  LetActorWalk(GetActor("Mother"), Direction.Up)
  For i = 1 To 3
    LetActorWalk(GetPrimaryActor(), Direction.Up)
  Next
  AddActor_MTStopped("Uncle", 17, 14, 0, [A_Uncle], ActorMotion.Up, Nothing)
  SetViewCenter(544, 160)
  FadeOut(0, 0, 0, 3000)
  DoMsgT({"そんな　ある日……"}, 2900)
  For i = 1 To 8
    LetActorWalk(GetActor("Uncle"), Direction.Up)
  Next
  DoMsgT({s_name, [TheHero].Name + "は　いるか？"}, 3500)
  LetActorTurn(GetPrimaryActor(), Direction.Down)
  DoMsgT({p_name, "あ　レナードさん"}, 3400)
  LetActorTurn(GetActor("Father"), Direction.Down)
  LetActorTurn(GetActor("Mother"), Direction.Down)
  DoMsgT({s_name, "ギュンターとテレーゼさんも", _
    "聞いてくれ　大事な話があるんだ"}, 6600)
  Sleep(1500)
  DoMsgT({s_name, "国王陛下が" + [TheHero].Name + "を", _
    "騎士として召集せよとのことだ"}, 7000)
  DoMsgT({p_name, "え？"}, 2700)
  If TestFlag("Medrod_1") Then
    DoMsgT({s_name, "アドルニアでの活躍を耳にされてな", _
      "おまえ　城を怪物から奪還したそうじゃないか"}, 8100)
  ElseIf TestFlag("NorthEvo") Then
    DoMsgT({s_name, "アドルニアでの活躍を耳にされてな", _
      "おまえ　都市を怪物から救ったそうじゃないか"}, 8100)
  End If
  DoMsgT({q_name, [TheHero].Name + "　本当なのか？"}, 3800)
  LetActorTurn(GetPrimaryActor(), Direction.Up)
  DoMsgT({p_name, "本当だけど……"}, 3400)
  LetActorTurn(GetPrimaryActor(), Direction.Down)
  DoMsgT({s_name, "騎士団のほうでも　お前を待っているぞ", _
    "なに　そのうち休暇取って　帰ってくればいいさ"}, 8100)
  DoMsgT({p_name, "………………"}, 3000)
  DoMsgT({q_name, [TheHero].Name + "　今すぐ出発するのだ"}, 3700)
  LetActorTurn(GetPrimaryActor(), Direction.Up)
  LetActorTurn(GetActor("Mother"), Direction.Right)
  DoMsgT({r_name, "あなた……"}, 3000)
  LetActorTurn(GetActor("Father"), Direction.Up)
  DoMsgT({q_name, "陛下のご命令なら　仕方ない"}, 4200)
  Sleep(1500)
  LetActorTurn(GetPrimaryActor(), Direction.Down)
  DoMsgT({p_name, "分かりました"}, 3100)
  LetActorTurn(GetActor("Mother"), Direction.Down)
  DoMsgT({s_name, "分かってくれて　ありがとう", _
    "では　行こうか"}, 5700)
  RunThread(EndingMovingProc, GetActor("Uncle"))
  RunThread(EndingMovingProc, GetPrimaryActor())
  Sleep(3000)
  DoMsgT({r_name, "わたし　心配……"}, 3500)
  DoMsgT({q_name, "なに　あいつも腕を上げたようだから", _
    "心配することはないさ"}, 6700)
  LetActorTurn(GetActor("Mother"), Direction.Right)
  DoMsgT({r_name, "そうじゃないの"}, 3100)
  LetActorTurn(GetActor("Father"), Direction.Left)
  Sleep(1500)
  DoMsgT({r_name, "何かとても大きな　悪いことが", _
    "起こりそうな気がするの"}, 6500)
  Sleep(1500)
  DoMsgT({q_name, "うむ……"}, 3000)
  LetActorTurn(GetActor("Father"), Direction.Down)
  DoMsgT({q_name, "最近は兵士の召集が多い", _
    "怪物もいなくなった今　なぜ……"}, 7000)
  LetActorTurn(GetActor("Mother"), Direction.Down)
  FadeInProc(0, 0, 0, 5000)
  Sleep(3000)
End_Roll:
  PutLabel((ss.X - 13 * 21) / 2, (ss.Y - 30) / 2 - 30, [F_MSG], Color.White, _
    "M O R T A L   R O A R", 1000, 5000, 2000)
  Sleep(3000)
  PutLabel((ss.X - 13 * 23) / 2, (ss.Y - 30) / 2 + 30, [F_MSG], Color.White, _
    "Presented by M.Kakumoto", 1000, 5000, 2000)
  Sleep(9000)
  PutLabel((ss.X - 13 * 31) / 2, (ss.Y - 30) / 2 - 30, [F_MSG], Color.White, _
    "Special Thanks - Exi no minasan", 1000, 5000, 2000)
  Sleep(3000)
  PutLabel((ss.X - 13 * 30) / 2, (ss.Y - 30) / 2 + 30, [F_MSG], Color.White, _
    "And thank you for your playing", 1000, 5000, 2000)
  Sleep(9000)
  PutLabel(ss.X - 14 * 6, ss.Y - 30, [F_MSG], Color.Pink, _
    "La Fin", 1000, 500000, 200000)
End Procedure
